<style type="text/css">
    select { width: 200px !important;}
</style>
<div>
    <form name="fbusca" action="" method="post">
        <input class="input-xlarge" type="text" name="cha_nome" placeholder="T&iacute;tulo e Conteúdo">
        <?php include "mod/combo/set_id.php"; ?>
        <?php include "mod/combo/cha_sta_id.php"; ?>
        <input class="span2" type="text" name="ini" placeholder="Data de In&iacute;cio" onfocus="showCalendarControl(this);">
        <input class="span2" type="text" name="fim" placeholder="Data de T&eacute;rmino" onfocus="showCalendarControl(this);">
        <input type="submit" name="btnBuscar" value="Buscar" class="btn">
    </form>
    
</div>

<div>

    <?php
    $sql = "SELECT chamado.cha_id,
    chamado.cha_nome,
    chamado.cha_msg,
    chamado.cha_data,
    chamado.cha_hora,
    setor.set_nome,
    setor.set_id,
    cliente.cli_code,
    cliente.cli_id,
    cliente.cli_nome,
    cliente.cli_guerra,
    cliente.cli_tel,
    cliente.cli_email,
    posto.pos_nome,
    local.loc_nome,
    local.loc_id2
    FROM chamado 
    INNER JOIN setor ON setor.set_id=chamado.set_id 
    INNER JOIN cliente ON cliente.cli_id=chamado.cli_id 
    LEFT JOIN posto ON posto.pos_id=cliente.pos_id 
    LEFT JOIN local ON local.loc_id=cliente.loc_id 
    WHERE chamado.cli_id='{$_SESSION['cli_id']}' AND chamado.status='1' $onde 
    ORDER BY chamado.cha_id DESC";
    $res = sql($sql);
    if (mysql_num_rows($res)>0){
    ?>
    <table class="table table-striped table-bordered table-hover" >

        <tr>
            <?php if (in_array(1,$_SESSION['per_id'])) { ?>
            <th width="200" height="40">A&ccedil;ões</th>
            <? } ?>
            <th width="70">N&ordm; de chamado</th>
            <th>T&iacute;tulo</th>
            <th width="160">Setor de atua&ccedil;&atilde;o</th>
            <th width="100">Status</th>
            <th width="90">Data/Hora (Z)</th>
        </tr>

        <?php
        $i=0;
        while($linha = mysql_fetch_array($res)){
            
            if ($linha['cli_guerra'] != "") { $nome = $linha['cli_guerra']; } else { $nome = $linha['cli_nome']; }
            
            $sql_acao = "SELECT cha_status.cha_sta_id,cha_status.cha_sta_nome,cha_status.cha_sta_cor,acao.aca_msg 
            FROM acao 
            INNER JOIN cha_status ON cha_status.cha_sta_id=acao.cha_sta_id 
            WHERE acao.cha_id='{$linha['cha_id']}' 
            ORDER BY acao.aca_id DESC";
            $res_acao = sql($sql_acao);
            $linha_acao = mysql_fetch_array($res_acao);
            $cha_sta_id = $linha_acao['cha_sta_id'];
            $aca_msg = $linha_acao['aca_msg'];
            $cha_id = $linha['cha_id'];
            $set_id = $linha['set_id'];
            $status = "
            <table border='0' width='100%'>
                <tr>
                    <td align='center' width='25'>
                        <div style='width: 20px;height: 20px; background-color:{$linha_acao['cha_sta_cor']}'></div>
                    </td>
                    <td>
                        <span class='color:{$linha_acao['cha_sta_cor']};font-weight:bold;'>{$linha_acao['cha_sta_nome']}</span>
                    </td>
                <tr>
            </table>";
            
            
        ?>
        <tr> 
            <?php if (in_array(1,$_SESSION['per_id'])) { ?>
            <td height="60" align="center">

                <input name="excluir[]" type="checkbox" value="<?=$linha['cha_id'];?>"/><i class="icon-trash"></i> Excluir
            
            </td>
            <? } ?>
            
            <td align="center" ><strong><?=$linha['cha_id']; ?></strong></td>
            <td>
                <?php echo "{$linha['cli_code']}&nbsp;&nbsp;-&nbsp;&nbsp;{$linha['pos_nome']}&nbsp;&nbsp;$nome - {$linha['cli_tel']}&nbsp;{$linha['cli_email']}&nbsp;{$linha['cli_sala']}";?>
                <hr>
                <a href="#detalhechamado<?=$i;?>" data-toggle="modal"><?=$linha['cha_nome']; ?></a><a href="#detalhechamado<?=$i;?>" data-toggle="modal" class="icon-edit pull-right"></a>
                <?php include "mod/detalhehelpdesk/index.php"; ?>
            </td>
            <td align="center" ><?=$linha['set_nome']; ?></td>    
            <td align="center"><?=$status;?></td>
            <td align="center" ><?=toDataBr($linha['cha_data'])."<br>".$linha['cha_hora'] . " Z"; ?></td>
        </tr>
        <?php 
        $i++;
        } 
        ?>
        
    </table>
    <?php } ?>

</div>
